/*
 * Copyright (c) 2022, tyustli
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2022-03-03     tyustli      first implementation
 */

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
    int row = 0;
    int column = 0;
    int *mutrix1 = NULL;
    int *mutrix2 = NULL;

    printf("请输入行数： ");
    scanf("%d", &row);
    printf("请输入列数： ");
    scanf("%d", &column);

    mutrix1 = (int *)malloc(row * column * sizeof(int));
    if (mutrix1 == NULL)
    {
        printf("no mem for mutrix1\r\n");
        goto __error_;
    }

    mutrix2 = (int *)malloc(row * column * sizeof(int));
    if (mutrix2 == NULL)
    {
        printf("no mem for mutrix2\r\n");
        goto __error_;
    }

    for (int i = 0; i < row; i++)
    {
        for (int j = 0; j < column; j++)
        {
            printf("input a%d%d ", i, j);
            scanf("%d", &mutrix1[i + j * row]);
        }
    }

    for (int i = 0; i < row; i++)
    {
        for (int j = 0; j < column; j++)
        {
            printf("input b%d%d ", i, j);
            scanf("%d", &mutrix2[i + j * row]);
        }
    }

    for (int i = 0; i < row; i++)
    {
        for (int j = 0; j < column; j++)
        {
            printf("output c%d%d ", i, j);
            printf("%d ", mutrix1[i + j * row] += mutrix2[i + j * row]);
        }
        printf("\r\n");
    }

__error_:
    if (mutrix1)
        free(mutrix1);

    if (mutrix2)
        free(mutrix2);

    return 0;
}

/********************** end of file **************************/
